#region Summary

// 
// Owner : JackieHan 
// 
// Solution : LearnSolution 
// 
// Project : JackieHan.NHibernate3.Test
// 
// File : TestUserInfo.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : Summary
// 
// History : 
//			2010-09-20 13:06:15	    Create 
// 

#endregion

#region Using

using System;
using System.Collections;
using System.Collections.Generic;
using JackieHan.NHibernate3.Domain;
using JackieHan.NHibernate3.Repository;
using NUnit.Framework;

#endregion

namespace JackieHan.NHibernate3.Test
{
    /// <summary> 
    /// Summary
    /// </summary>
    [TestFixture]
    public class TestUserInfo
    {
        private UserInfoRepository db = new UserInfoRepository();

        [Test]
        public void TestSaveUser()
        {
            for (int i = 0; i < 10000; i++)
            {
                UserInfo item = new UserInfo
                                    {
                                        Age = i,
                                        CreateDate = DateTime.Now,
                                        Creator = "admin",
                                        LastUpdateDate = DateTime.Now,
                                        Name = "jackie" + i,
                                        Updator = "admin",
                                        Version = 1
                                    };
                db.Save(item);
            }
        }

        [Test]
        public void TestGetAll()
        {
            IList<UserInfo> basicUsers = db.GetAll();
            IList<UserInfo> linqUsers = db.GetAllByLinq();

            Assert.That(basicUsers.Count, Is.EqualTo(linqUsers.Count));
        }

        [Test]
        public void TestGetByCondition()
        {
            IList<UserInfo> basicUsers = db.GetUsersByCondition();
            IList<UserInfo> linqUsers = db.GetUserByConditionWhitLinq();

            Assert.That(1, Is.EqualTo(linqUsers.Count));
            Assert.That(basicUsers.Count, Is.EqualTo(linqUsers.Count));
        }

        [Test]
        public void TestGetByExamle()
        {
            var basicUsers = db.GetUserColumn();
            var linqUsers = db.GetUserColumnWithLinq();

            Assert.That(1, Is.EqualTo(linqUsers.Count));
            Assert.That(basicUsers.Count, Is.EqualTo(linqUsers.Count));
        }

        [Test]
        public void TestGetUserWithSkip()
        {
            IList<UserInfo> users = db.GetUserWithSkipAndTake();
            Assert.AreEqual(3, users.Count);
            Assert.AreEqual(2, users[0].Age);
            Assert.AreEqual(3, users[1].Age);
            Assert.AreEqual(4, users[2].Age);
        }

        [Test]
        public void TestGetSortedUser()
        {
            IList<UserInfo> users = db.GetSortedUser();
            Assert.AreEqual(9999, users[0].Age);
        }

        [Test]
        public void TestGetByGroup()
        {
            ICollection collection = db.GetByGroup();
            Assert.AreEqual(1, collection.Count);
        }
    }
}